import axios from 'axios';
import { UserState } from '@/store/modules/user/types';
import { page } from '@/types/global';

export interface LoginData {
  username: string;
  password: string;
}

export function login(data: LoginData): Promise<string> {
  return axios.post('/auth/login', {}, { params: data });
}

export function logout() {
  return axios.post('/auth/logout');
}

export function getUser(): Promise<UserState> {
  return axios.get('/upms/user');
}

export function addUser(data: any) {
  return axios.post('/upms/user', data);
}

export function updateUser(data: any) {
  return axios.put('/upms/user', data);
}
export function delUser(id: string) {
  return axios.delete(`/upms/user/${id}`);
}

export function getUserPage(params: any): Promise<page> {
  return axios.get('/upms/user/page', {
    params,
  });
}

export function changePwd(id: string, password: string) {
  return axios.put('/upms/user/password', { id, password });
}
